from mediator import mediator
from mediator . tests . test_assistant import make_mediator_test_keyword_args

class browser_logic_fake :
    def __init__ ( self ) :
        self . _hide_browser = False
        self . _receive_knowledge_base = None
        self . _key_down = False
        self . _key_up = False
        self . _key_escape = False
        self . _table_row_click = None
        self . _rename_base_in_browser = False
        self . _copy_base_in_browser = False
        self . _entry_focus = False
        self . _entry_unfocus = False
        self . _action_gui_button = False
        self . _title_text = None
        self . _action_text = None
        self . _action_title_name_text = None
        self . _only_unique_names_mode = None
        self . _unique_or_existing_names_mode = False
        self . _remove_action_part_when_no_entries = False
        self . _keep_action_part_when_no_entries = False
        self . _entry_text_in_browser_reply = None
    def entry_text_in_browser_reply ( self , text ) :
        self . _entry_text_in_browser_reply = text
    def show_browser ( self ) :
        mediator_browser_logic_tests . _call_history += [ browser_logic_fake . show_browser ]
    def hide_browser ( self ) :
        self . _hide_browser = True
    def receive_knowledge_base ( self , name , creation_time , modification_time , size ) :
        self . _receive_knowledge_base = [ name , creation_time , modification_time , size ]
    def on_key_down ( self ) :
        self . _key_down = True
    def on_key_up ( self ) :
        self . _key_up = True
    def on_key_return ( self ) :
        mediator_browser_logic_tests . _call_history += [ [ browser_logic_fake . on_key_return ] ]
    def on_key_escape ( self ) :
        self . _key_escape = True
    def on_table_row_click ( self , row ) :
        self . _table_row_click = row
    def on_browser_entry_focus ( self ) :
        self . _entry_focus = True
    def on_browser_entry_unfocus ( self ) :
        self . _entry_unfocus = True
    def on_browser_action_gui_button ( self ) :
        self . _action_gui_button = True
    def rename_base_in_browser ( self ) :
        self . _rename_base_in_browser = True
    def copy_base_in_browser ( self ) :
        self . _copy_base_in_browser = True
    def configure_title_text_for_browser ( self , title_text ) :
        self . _title_text = title_text
    def configure_action_text_for_browser ( self , action_text ) :
        self . _action_text = action_text
    def configure_action_title_name_text_for_browser ( self , action_title_name_text ) :
        self . _action_title_name_text = action_title_name_text
    def configure_only_unique_names_mode_for_browser ( self , already_exists_text ) :
        self . _only_unique_names_mode = already_exists_text
    def configure_unique_or_existing_names_mode_for_browser ( self ) :
        self . _unique_or_existing_names_mode = True
    def configure_title_text_when_no_entries_for_browser ( self , title_text ) :
        self . _title_text_when_no_entries = title_text
    def configure_remove_action_part_when_no_entries_for_browser ( self ) :
        self . _remove_action_part_when_no_entries = True
    def configure_keep_action_part_when_no_entries_for_browser ( self ) :
        self . _keep_action_part_when_no_entries = True

class arbitrary_module_fake :
    def show_browser ( self ) :
        mediator_browser_logic_tests . _call_history += [ arbitrary_module_fake . show_browser ]
    def hide_browser ( self ) :
        pass
    def receive_knowledge_base ( self , name , creation_time , modification_time , size ) :
        pass
    def on_key_down ( self ) :
        pass
    def on_key_up ( self ) :
        pass
    def on_key_return ( self ) :
        mediator_browser_logic_tests . _call_history += [ arbitrary_module_fake . on_key_return ]
    def on_key_escape ( self ) :
        pass
    def on_table_row_click ( self , row ) :
        pass
    def entry_text_in_browser_reply ( self , text ) :
        pass

class mediator_browser_logic_tests : 
    'mediator_browser_logic'
    def __init__ ( self , test ) :
        mediator_browser_logic_tests . _call_history = [ ]
        self . _test = test
        self . _browser_logic = browser_logic_fake ( )
        self . _mediator = mediator ( )
        self . _mediator . register_modules ( ** make_mediator_test_keyword_args \
            ( 'browser_logic' 
            , self . _browser_logic 
            , arbitrary_module_fake
            ) )
    def test_show_browser ( self ) :
        self . _mediator . show_browser ( )
        self . _test . assume_equal ( mediator_browser_logic_tests . _call_history [ - 1 ] , browser_logic_fake . show_browser )
    def test_hide_browser ( self ) :
        self . _mediator . hide_browser ( )
        self . _test . assume_true ( self . _browser_logic . _hide_browser )
    def test_receive_knowledge_base ( self ) :
        self . _mediator . receive_knowledge_base ( 'my name' , 'my creation time' , 'my modification time' , 'my size' )
        self . _test . assume_equal ( self . _browser_logic . _receive_knowledge_base ,
            [ 'my name'
            , 'my creation time'
            , 'my modification time'
            , 'my size'
            ] )
    def test_on_key_down ( self ) :
        self . _mediator . on_key_down ( )
        self . _test . assume_true ( self . _browser_logic . _key_down )
    def test_on_key_up ( self ) :
        self . _mediator . on_key_up ( )
        self . _test . assume_true ( self . _browser_logic . _key_up )
    def test_on_key_return ( self ) :
        self . _mediator . on_key_return ( )
        self . _test . assume_equal ( mediator_browser_logic_tests . _call_history [ 1 ] ,
            [ browser_logic_fake . on_key_return ]
        )
    def test_on_key_escape ( self ) :
        self . _mediator . on_key_escape ( )
        self . _test . assume_true ( self . _browser_logic . _key_escape )
    def test_on_table_row_click ( self ) :
        self . _mediator . on_table_row_click ( 'my row' )
        self . _test . assume_equal ( self . _browser_logic . _table_row_click , 'my row' )
    def test_on_browser_entry_focus ( self ) :
        self . _mediator . on_browser_entry_focus ( )
        self . _test . assume_true ( self . _browser_logic . _entry_focus )
    def test_on_browser_entry_unfocus ( self ) :
        self . _mediator . on_browser_entry_unfocus ( )
        self . _test . assume_true ( self . _browser_logic . _entry_unfocus )
    def test_on_browser_action_gui_button ( self ) :
        self . _mediator . on_browser_action_gui_button ( )
        self . _test . assume_true ( self . _browser_logic . _action_gui_button )
    def test_rename_base_in_browser ( self ) :
        self . _mediator . rename_base_in_browser ( )
        self . _test . assume_true ( self . _browser_logic . _rename_base_in_browser )
    def test_copy_base_in_browser ( self ) :
        self . _mediator . copy_base_in_browser ( )
        self . _test . assume_true ( self . _browser_logic . _copy_base_in_browser )
    def test_configure_title_text_for_browser ( self ) :
        self . _mediator . configure_title_text_for_browser ( 'my title' )
        self . _test . assume_equal ( self . _browser_logic . _title_text , 'my title' )
    def test_configure_action_text_for_browser ( self ) :
        self . _mediator . configure_action_text_for_browser ( 'my action' )
        self . _test . assume_equal ( self . _browser_logic . _action_text , 'my action' )
    def test_configure_action_title_name_text_for_browser ( self ) :
        self . _mediator . configure_action_title_name_text_for_browser ( 'my action title' )
        self . _test . assume_equal ( self . _browser_logic . _action_title_name_text , 'my action title' )
    def test_configure_only_unique_names_mode_for_browser ( self ) :
        self . _mediator . configure_only_unique_names_mode_for_browser ( 'my already exists' )
        self . _test . assume_equal ( self . _browser_logic . _only_unique_names_mode , 'my already exists' )
    def test_configure_unique_or_existing_names_mode_for_browser ( self ) :
        self . _mediator . configure_unique_or_existing_names_mode_for_browser ( )
        self . _test . assume_true ( self . _browser_logic . _unique_or_existing_names_mode )
    def test_configure_title_text_when_no_entries_for_browser ( self ) :
        self . _mediator . configure_title_text_when_no_entries_for_browser ( 'my title' )
        self . _test . assume_equal ( self . _browser_logic . _title_text_when_no_entries , 'my title' )
    def test_configure_remove_action_part_when_no_entries_for_browser ( self ) :
        self . _mediator . configure_remove_action_part_when_no_entries_for_browser ( )
        self . _test . assume_true ( self . _browser_logic . _remove_action_part_when_no_entries )
    def test_configure_keep_action_part_when_no_entries_for_browser ( self ) :
        self . _mediator . configure_keep_action_part_when_no_entries_for_browser ( )
        self . _test . assume_true ( self . _browser_logic . _keep_action_part_when_no_entries )
    def test_entry_text_in_browser_reply ( self ) :
        self . _mediator . entry_text_in_browser_reply ( 'my text' )
        self . _test . assume_equal ( self . _browser_logic . _entry_text_in_browser_reply , 'my text' )
